""" 用类实现一个日志装饰器,分发并写日志 """
from functools import wraps

class logit():
    def __init__(self, file_path):
        self.file_path = file_path
    
    def __call__(self, func):
        @wraps(func)
        def wrapped_function(*args, **kwargs):
            log_string = func.__name__+" was called"
            print(log_string)
            with open(self.file_path, "w") as f:
                f.write(log_string + "\n")
            self.notify()
            return func(*args, **kwargs)
        return wrapped_function
    def notify(self):
        print("notify you")

@logit("log_class.log")
def decorated_function(name, age):
    print(name, age)

decorated_function("glx", "forever 18")

